package com.wanglibao.woodtrade.woodtrade.ui.fragment.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.ui.fragment.adapter.model.ShopItem;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by lugg on 2016/5/14.
 */
public class HomeFragmentHotShopListViewAdapter extends BaseAdapter {

    public Context context;
    public ShopItem shopItem;

    public HomeFragmentHotShopListViewAdapter(Context context, ShopItem shopItem) {
        this.context = context;
        this.shopItem = shopItem;
    }

    @Override
    public int getCount() {
        return shopItem.getList().size();
    }

    @Override
    public Object getItem(int position) {
        return shopItem.getList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null){
            convertView = View.inflate(context,R.layout.item_list_fragment_home_hot_shop,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        ShopItem.ListBean listBean = shopItem.getList().get(position);
        ImageOptions imageOptions = new ImageOptions.Builder().setLoadingDrawable(context.getResources().getDrawable(R.mipmap.ic_home_shopping))
                .setFailureDrawable(context.getResources().getDrawable(R.mipmap.ic_home_shopping)).
                        setCircular(true).build();
        x.image().bind(viewHolder.imgView,listBean.getLogo_img_url(),imageOptions);
        viewHolder.name.setText(listBean.getCompany());
        return convertView;
    }

    class ViewHolder{
        public ViewHolder(View view) {
            ButterKnife.bind(this,view);
        }

        @Bind(R.id.sdv_item_list_fragment_home_hot_shop_img)
        ImageView imgView;
        @Bind(R.id.tv_item_list_fragment_home_hot_shop_name)
        TextView name;
    }
}
